package org.dromara.solonplugins.job.test2.job;

import org.dromara.solonplugins.job.IJobExecutor;
import org.dromara.solonplugins.job.IJobHandler;
import org.dromara.solonplugins.job.annotation.JobHandler;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 项目启动会自动注册@JobHandler标识的Job
 *
 * @author: aoshiguchen
 */
@Component
@JobHandler(name = "JobDemo3", cron = "0/5 * * * * ?")
public class JobDemo3 implements IJobHandler {
    private static final Logger log = LoggerFactory.getLogger(JobDemo3.class);

    @Inject
    private IJobExecutor jobExecutor;

    @Override
    public void execute(String param) throws Exception {
        log.info("JobDemo3 执行一次后停止");

        /**
         * 停止job任务
         * 实际场景下，一般是Job管理界面点击停止任务后触发。
         * 对应的，可以使用jobExecutor.add(xxx)来启动一个任务。
         * jobExecutor.trigger 手动触发任一次务执行
         */
        jobExecutor.stop("JobDemo3");
    }

}
